package sg.edu.nus.iss.cats.dataaccess.hibernate;

import java.util.List;

import sg.edu.nus.iss.cats.dataaccess.DAOException;
import sg.edu.nus.iss.cats.dataaccess.DAOUpdateException;
import sg.edu.nus.iss.cats.dataaccess.EmployeeDAO;
import sg.edu.nus.iss.cats.exception.HibernateAccessLayerException;
import sg.edu.nus.iss.cats.model.Employee;

public class EmployeeDAOImpl extends AbstractDao implements EmployeeDAO {

	public EmployeeDAOImpl() {
		super();
	}

	public Employee findEmployee(String employeeId) throws DAOException {

		System.out.println("Finding employee" + employeeId);
		try {
			return ((Employee) super.find(Employee.class, employeeId));

		} catch (Throwable t) {
			throw new HibernateAccessLayerException(t.toString());

		}

	}

	public Employee[] findEmployeesByManager(String managerId)
			throws DAOException {
		

		try {
			List ls = super.findByCategory(Employee.class,
					HibernateConstants.e_managerId, managerId);
			Employee[] result = new Employee[ls.size()];
			ls.toArray(result);
			return (result);
		} catch (Throwable t) {
			throw new DAOException(t.toString());
		}

	}

	public void insertEmployee(Employee employee) throws DAOException {
		throw new DAOException("Not yet implemented!");
	}

	public void updateEmployee(Employee employee) throws DAOUpdateException {
		throw new DAOUpdateException("Not yet implemented!");
	}

	public void deleteEmployee(Employee employee) throws DAOException {
		throw new DAOException("Not yet implemented!");
	}

}